function JsonRenderer() {
    this.builder = new Builder();
}

JsonRenderer.prototype.begin = function(data, deep) {
    if (data instanceof Array) {
        this.builder.push('[', deep);
    } else if (typeof data === 'string') {
        this.builder.appendLastLine('"', deep);
    } else if (data instanceof Object) {
        this.builder.push('{', deep);
    }

}

JsonRenderer.prototype.end = function(data, deep) {
    if (data instanceof Array) {
        this.builder.push(']', deep);
    } else if (typeof data === 'string') {
        this.builder.appendLastLine('"', deep);
    } else if (data instanceof Object) {
        this.builder.push('}', deep);
    }
}

JsonRenderer.prototype.body = function(data, deep) {
    if (data instanceof Array) {
        for ( var i = 0; i < data.length; i++) {
            if (i > 0) {
                this.builder.appendLastLine(', ');
            }
            this.encode(data[i], deep + 1);
        }
    } else if(typeof data === 'string') {
        this.builder.appendLastLine(data);
    } else if (data instanceof Object) {
        for ( var attr in data) {
            this.builder.push(attr, deep + 1);
            this.builder.appendLastLine(' : ');
            this.encode(data[attr], deep + 1);
        }
    } else {
        this.builder.appendLastLine(data);
    }
}

JsonRenderer.prototype.encode = function(data, deep) {
    var d = deep || 0;
    this.begin(data, d);
    this.body(data, d);
    this.end(data, d);
    return this.builder;
}